/*******************************************************************************
 * Copyright (c) 2002 Boris Pruessmann and others. All rights reserved. This
 * program and the accompanying materials are made available under the terms of
 * the Common Public License v0.5 which accompanies this distribution, and is
 * available at http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors: Boris Pruessmann - Initial implementation
 ******************************************************************************/
package net.sourceforge.perforce.internal.api;

import java.io.InputStream;

import net.sourceforge.perforce.core.api.IInfoResult;
import net.sourceforge.perforce.core.internal.api.Info;

/**
 * @author <a href="mailto:bpruessmann@users.sourceforge.net">Boris
 *         Pruessmann</a>
 * @version $Revision: 488 $
 */
public class InfoTest extends ClientUserTestCase {
  // ---------------------------------------------------------------------------
  // Private Variables

  /** Stores the ClientUser instance to test. */
  private Info clientUser;

  // -------------------------------------------------------------------------
  // Public Constructors

  /**
   * Constructor for InfoTest.
   * 
   * @param name the name of the test.
   */
  public InfoTest(String name) {
    super(name);
  }

  //----------------------------------------------------------------------------
  // -- Public Methods

  /** Tests Info with a valid result. */
  public void testValidResult() throws Exception {
    InputStream script = getClass().getResourceAsStream("info_validResult.xml");
    executeScript(script, clientUser);

    assertTrue(clientUser.getStatus().isOK());

    IInfoResult result = clientUser.getResult();
    assertEquals("bp", result.getUserName());
    assertEquals("pruessm-b-w2k", result.getClientName());
    assertEquals("PRUESSM-B-W2K", result.getClientHost());
    assertEquals("c:\\Sources\\Perforce", result.getClientRoot());
    assertEquals("192.168.0.7:1277", result.getClientAddress());
    assertEquals("public.perforce.com:1666", result.getServerAddress());
    assertEquals("/raid/perforce", result.getServerRoot());
    assertEquals("2002/11/10 12:54:59 CET", result.getServerDate());
    assertEquals("P4D/FREEBSD4/2002.1/33156 (2002/05/07)", result.getServerVersion());
    assertEquals("Perforce Public Depot 400 users (expires 2002/12/31)", result.getServerLicense());
  }

  // ---------------------------------------------------------------------------
  // Protected Mehtods

  @Override
  protected void setUp() throws Exception {
    super.setUp();

    clientUser = Info.newInstance(null);
  }
}
